<template>
    <div>
        <h1 style="text-align:center">评论</h1>
        {{user.code}}
        <el-table :data="articleList.data"  style="margin-left:650px;width: 100%">
            <el-table-column flexed prop="name" label="用户名" width="150"></el-table-column>
            <el-table-column flexed prop="content" label="评论" width="350"></el-table-column>
            <el-table-column flexed label="赞" width="50">
                <template flexed slot-scope="scope">
                    <img v-if="show(scope.row)" @click="getGood(scope.row)" :src="'../assets/'+this.imgUrl" style="width: 30px;height: 30px">
                </template>
            </el-table-column>
            <el-table-column flexed prop="num" width="100"></el-table-column>
        </el-table><br>
    </div>
</template>

<script>
import {mapState,mapMutations,mapActions} from "vuex"
import {getUser,refreshToken,getGreat,showAll} from "../service/kaoshiUser"
export default {
    data(){
        return{
            imgUrl:"zan.png",
            user:{},
        }
    },
    computed:{
        
    },
    methods:{
         show(row){
            for(let i = 0; i<this.user.size;i++){
                if(row.articleId == this.user.articleBeans[i].articleId){
                    this.imgUrl = "zan_active.png"
                }
            }
        },

         async getGood(row){
            await this.ajax.getSubmit("/project/users/gerGreat",{articleId:row.articleId,userId:this.user.userId}); 

         }
       
    },
    async created(){
       
        let response = await getUser(this.$cookies.get('token'));
        console.log("index:",response)
        if(response.status == 2009){
            // 刷新token后将新的token保存到cookie中
            console.log("refreshToken",this.$cookies.get('refreshToken'));
            let newTokenResponse = await refreshToken(this.$cookies.get('refreshToken'));
            this.$cookies.set("token",newTokenResponse.data);
            response = await getUser(newTokenResponse.data);
        }
        if(response.status != 1){
            this.$router.push("/login");
        }else{
            this.user = response;
        }
        this.showAll();
    }
}
</script>

<style>

</style>